package com.dsfa.conf;

//import com.dsfa.filter.WsOutInterceptor;
//import com.dsfa.filter.WsVerifyInInterceptor;
import com.dsfa.wsServ.IWSServer;
import com.dsfa.wsServ.WSServerImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.*;

import javax.xml.ws.Endpoint;

/**
 * @Description: WebService代理配置
 * @ClassName: WebserviceConfig
 * @Author: wangdm
 * @Date: 2024/1/26
 */
@Configuration
public class WebServiceConfig {
    @Value("${webservices.agentSpace:}")
    private String agentSpace;
    @Value("${webservices.agentAddrWS:}")
    private String agentAddr;

    @Bean
    public ServletRegistrationBean dispatcherServletForWebservice() {
        return new ServletRegistrationBean(new CXFServlet(), this.agentSpace);
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public IWSServer wsService() {
        return new WSServerImpl();
    }

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), wsService());
        //endpoint.getInInterceptors().add(new WsVerifyInInterceptor());
        //endpoint.getOutInterceptors().add(new WsOutInterceptor());//数据量大的时候处理有问题，弃用
        endpoint.publish( this.agentAddr);
        return endpoint;
    }
    /*@Bean
    public Endpoint endpoint2()
    {
        EndpointImpl endpoint = new EndpointImpl(springBus(), twoService());
        endpoint.publish("/TwoServiceForTest");
        return endpoint;
    }*/
}
